<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Scenario Programming</title>
</head>

<body text="#FFFFFF" bgcolor="#000000" style="font-family: Verdana; font-size: 10pt" link="#00FFFF" vlink="#00FFFF" alink="#00FFFF">

<p><font size="3"><b>Dynamic Scenarios</b></font></p>
<font SIZE="2">
<p>Dynamic Scenarios are Scenarios that contain custom behavior that you program 
in the ProcessImpulse method.&nbsp; The ProcessImpulse method is executed every
<a href="Impulses%20and%20Movement.htm">Impulse</a> of the game by the host 
player in a MultiPlayer game.</p>
<p>The Scenario class contains a property called DynamicEvents, which is an 
IDynamicEvents interface type.&nbsp; This interface contains a set of methods 
that you can call to perform dynamic actions within a game.&nbsp; These actions 
are communicated to other players in a MultiPlayer game.&nbsp; For example, you 
could move the first player's Capital StarSystem one square to the left by using 
the RelocateObject method:</p>
<p>StarSystem capital = Game.Players[0].Capital;<br>
DynamicEvents.RelocateObject(capital, capital.X - 1, capital.Y);</p>
<p><b><font color="#FF0000">Warning</font></b>: Do not modify any game state 
without using a DynamicEvents method!&nbsp; If you do, the changes will 
not propagate to others in a Multiplayer game.</p>
<font SIZE="2" COLOR="#00FFFF"><b>
<p>public</b> <b>virtual</b> <b>void</b></font><font SIZE="2"> ProcessImpulse(</font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> 
impulse)<br>
SV5 calls this method in the host player's Scenario object on every Impulse.&nbsp; 
Within your implementation of this method, you can examine the internal game state by using 
the Game property, which returns an instance of the SVGame class.&nbsp; This 
class contains all of the internal state of the game, including lists of 
StarShip objects (the StarShips property), StarSystem objects (the StarSystems 
property) and the ability 
to examine the map (GetTerrain and GetObjectAt methods).&nbsp; Use Visual Studio 
Intellisense to examine the various public properties and methods available in 
the Game object.&nbsp; 
If you have questions about how to locate a specific piece of game state 
information, please post it to the <a href="http://www.runboard.com/bsiliconcommandergames">Silicon 
Commander Games message board</a>.</font></p>
<p><font color="#FFFF00"><b>DynamicEvents property</b></font></p>
<p>The DynamicEvents property contains the following methods that you can call 
within ProcessImpulse.&nbsp; They allow you to modify various elements in the 
game to create truly dynamic Scenarios.</p>
<p>Example:</p>
<p>//Any StarShips in this area move randomly 1 square<br>
Rectangle noMansLand = new Rectangle(50, 50, 10, 10);<br>
foreach(StarShip ship in Game.StarShips)<br>
&nbsp;&nbsp; if (noMansLand.Contains(ship.Location))<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int x = Random(-1, 1);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int y = Random(-1, 1);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DynamicEvents.MoveStarShip(ship, ship.x + x, 
ship.y + y);<br>
&nbsp;&nbsp; }</p>
<font SIZE="2" COLOR="#00FFFF"><b>
<p>public</b> <b>void</b></font><font SIZE="2"> AdjustShipValues(</font><font SIZE="2" COLOR="#00FFFF">StarShip</font><font SIZE="2"> 
ship, </font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> 
engines, </font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> 
maxEngines, </font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> 
value, </font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> 
maxValue, </font><font SIZE="2" COLOR="#00FFFF"><b>bool</b></font><font SIZE="2"> 
repsectFixedValues)<br>
Adjusts the current, and maximum, engine and primary system values for the 
specified StarShip.&nbsp; If respectFixedEngineValues is false, the method even 
allows you to override the normal fixed engine values of StarShips (such as the 
E1 Emines) and assign &quot;values&quot; to StarShips that normally don't have them (like 
Drones).&nbsp; See the HighEnergy.cs Scenario for an example.</font></p>
<font SIZE="2" COLOR="#00FFFF"><b>
<p>public</b> <b>void</b></font><font SIZE="2"> AdjustStarSystemValues(</font><font SIZE="2" COLOR="#00FFFF">StarSystem</font><font SIZE="2"> 
system, </font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> 
value, </font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> 
scanners, </font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> 
shields, </font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> 
resources)<br>
Adjusts the Value, Scanners, Shields, and Resources of a specified StarSystem.&nbsp; 
You can pass a -1 to any of these parameters if you do not want them to be 
adjusted.</p>
</font>
<font SIZE="2" COLOR="#00FFFF"><b>
<p>public</b> BlackHole</font><font SIZE="2"> CreateBlackHole(</font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> 
x, </font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> y, <b>
<font color="#00FFFF">int</font></b> radius)<br>
Creates a new BlackHole on the map at the specified location.&nbsp; The &quot;radius&quot; 
parameter indicates how close StarShips need to get before getting pulled toward 
the BlackHole.</p>
</font><font SIZE="2" COLOR="#00FFFF"><b>
<p>public</b> <b>void</b></font><font SIZE="2"> CreateExplosion(</font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> 
x, </font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> y,
</font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> 
particles, </font><font SIZE="2" COLOR="#00FFFF">Color</font><font SIZE="2"> 
startColor, </font><font SIZE="2" COLOR="#00FFFF">Color</font><font SIZE="2"> 
endColor, </font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> 
startDiam, </font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> 
endDiam, </font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> 
lifeSpan)<br>
Produces an explosion on the map, and optionally plays an explosion sound.&nbsp; 
The explosion is particle-based, and you control the various aspects of it via 
the parameters.&nbsp; The number of particles in the explosion is determined by 
the &quot;particles&quot; parameter.&nbsp; Each particle will be a random color ranging 
from &quot;startColor&quot; to &quot;endColor&quot;.&nbsp; Note that you can apply alpha values to &quot;startColor&quot; 
and &quot;endColor&quot; to get more interesting effects (for example, Color.FromArgb(20, 
Color.Black) for &quot;startColor&quot; and Color.FromArgb(255,Color.Red) for &quot;endColor&quot;.)&nbsp; 
Each particle is a random size in pixels between &quot;startDiam&quot; and &quot;endDiam&quot;.&nbsp; 
The explosion's life span is controlled by the &quot;lifeSpan&quot; parameter, expressed 
in animation cycles.</font></p>
<font SIZE="2" COLOR="#00FFFF"><b>
<p>public</b> Pulsar</font><font SIZE="2"> CreatePulsar(</font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> 
x, </font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> y)<br>
Creates a new pulsar on the map.</p>
</font><font SIZE="2" COLOR="#00FFFF"><b>
<p>public</b> StarShip</font><font SIZE="2"> CreateStarShip(</font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> 
x, </font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> y,
</font><font SIZE="2" COLOR="#00FFFF">Player</font><font SIZE="2"> owner, </font>
<font SIZE="2" COLOR="#00FFFF">StarShipType</font><font SIZE="2"> shipType,
</font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> engines,
</font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> extra,
</font><font SIZE="2" COLOR="#00FFFF"><b>bool</b></font><font SIZE="2"> cloaked)<br>
Creates a new StarShip on the map at the specified location.</p>
</font><font SIZE="2" COLOR="#00FFFF"><b>
<p>public</b> StarSystem</font><font SIZE="2"><font color="#00FFFF"> </font>
CreateStarSystem(</font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> 
x, </font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> y,
</font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> value,
</font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> shields,
</font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> scanners,
</font><font SIZE="2" COLOR="#00FFFF"><b>double</b></font><font SIZE="2"> 
resources)<br>
Creates a new StarSystem at the specified location with the specified 
properties.&nbsp; You can change aspects of the StarSystem further by modifying 
its properties, such as Name, BonusShipType and BonusValue.</font></p>
<font SIZE="2" COLOR="#00FFFF">
<p>UDO</font><font SIZE="2"> CreateUDO(</font><font SIZE="2" COLOR="#00FFFF"><b>string</b></font><font SIZE="2"> 
name, </font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> x,
</font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> y, </font>
<font SIZE="2" COLOR="#00FFFF"><b>string</b></font><font SIZE="2"> imageName,
</font><font SIZE="2" COLOR="#00FFFF"><b>bool</b></font><font SIZE="2"> 
autoPickup, </font><font SIZE="2" COLOR="#00FFFF"><b>bool</b></font><font SIZE="2"> 
ignoreBlackHoles, </font><font SIZE="2" COLOR="#00FFFF"><b>bool</b></font><font SIZE="2"> 
isTaggable, </font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> 
frameCount, </font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> 
frameDelay, </font><font SIZE="2" COLOR="#00FFFF"><b>bool</b></font><font SIZE="2"> 
randomizeFrames, </font><font SIZE="2" COLOR="#00FFFF"><b>bool</b></font><font SIZE="2"> 
randomizeDelay)<br>
Allows you to create a new <a href="UDOs.htm">UDO</a> during the game.&nbsp; All 
of the UDO properties are contained in parameters of this method.&nbsp; 
Remember, you cannot change a UDO's properties after it is created, although you 
can move it or relocate it using the MoveUDO or RelocateObject methods.</p>
</font>
<font SIZE="2" COLOR="#00FFFF"><b>
<p>public</b> Wormhole</font><font SIZE="2"> CreateWormhole(</font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> 
x, </font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> y,
</font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> destX,
</font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> destY)<br>
Creates a new Wormhole on the map, with the specified location and destination 
point.</font></p>
<font SIZE="2" COLOR="#00FFFF"><b>
<p>public</b> <b>void</b></font><font SIZE="2"><font color="#00FFFF"> </font>
DamageStarShip(</font><font SIZE="2" COLOR="#00FFFF">StarShip</font><font SIZE="2"> 
ship, </font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> 
damage)<br>
Inflicts damage to a StarShip in the amount specified in the &quot;damage&quot; parameter.&nbsp; 
Will destroy the StarShip if Engines or Primary System falls below zero.&nbsp; 
This is the preferred method for reducing a StarShip's strength, although you 
can also AdjustStarShipValues, and not get the explosive effect.</font></p>
<font SIZE="2" COLOR="#00FFFF"><b>
<p>public</b> <b>void</b></font><font SIZE="2"><font color="#00FFFF"> </font>
DestroyStarShip(</font><font SIZE="2" COLOR="#00FFFF">StarShip</font><font SIZE="2"> 
ship)<br>
Destroys the specified StarShip outright.</font></p>
<font SIZE="2" COLOR="#00FFFF"><b>
<p>public</b> <b>void</b></font><font SIZE="2"> DisplayMessage(</font><font SIZE="2" COLOR="#00FFFF"><b>string</b></font><font SIZE="2"> 
msg)<br>
Displays a Scenario message on the map the the player will have to clear by 
clicking an OK button.&nbsp; You should only call this method on a specific 
numeric Impulse, or when a specific event occurs that will not be repeated.&nbsp; 
Otherwise, the message will continually appear on top of the map.</font></p>
<font SIZE="2" COLOR="#00FFFF"><b>
<p>void</b></font><font SIZE="2"> EjectUDO(</font><font SIZE="2" COLOR="#00FFFF">StarShip</font><font SIZE="2"> 
ship, </font><font SIZE="2" COLOR="#00FFFF">UDO</font><font SIZE="2"> udo)<br>
Causes the specified StarShip to eject the specified <a href="UDOs.htm">UDO</a> 
it is carrying.</p>
</font>
<font SIZE="2" COLOR="#00FFFF"><b>
<p>public</b> <b>void</b></font><font SIZE="2"> MoveStarShip(</font><font SIZE="2" COLOR="#00FFFF">StarShip</font><font SIZE="2"> 
ship, </font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> x,
</font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> y)<br>
Causes a StarShip to smoothly move toward the specified destination.</font></p>
<font SIZE="2" COLOR="#00FFFF"><b>
<p>void</b></font><font SIZE="2"> MoveUDO(</font><font SIZE="2" COLOR="#00FFFF">UDO</font><font SIZE="2"> 
udo, </font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> x,
</font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> y)<br>
Causes a <a href="UDOs.htm">UDO</a> to smoothly move toward the specified 
destination.</p>
</font><font SIZE="2" COLOR="#00FFFF"><b>
<p>void</b></font><font SIZE="2"> PickUpUDO(</font><font SIZE="2" COLOR="#00FFFF">StarShip</font><font SIZE="2"> 
ship, </font><font SIZE="2" COLOR="#00FFFF">UDO</font><font SIZE="2"> udo)<br>
Causes the specified StarShip to pick up the specified <a href="UDOs.htm">UDO</a>.</p>
</font><font SIZE="2" COLOR="#00FFFF"><b>
<p>public</b> <b>void</b></font><font SIZE="2"><font color="#00FFFF"> </font>
RelocateObject(</font><font SIZE="2" COLOR="#00FFFF">SVMapObject</font><font SIZE="2"> 
svm, </font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> x,
</font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> y)<br>
Use this method to re-position an object on the map.&nbsp; The SVMapObject is 
the base class for objects that can be found on the map.&nbsp; The following 
classes are derived from SVMapObject: StarShip, StarSystem, BlackHole, Wormhole, Pulsar, 
and <a href="UDOs.htm">UDO</a>.</font></p>
<font SIZE="2" COLOR="#00FFFF"><b>
<p>public</b> <b>void</b></font> <font SIZE="2">RemoveObject(</font><font SIZE="2" COLOR="#00FFFF">SVMapObject</font><font SIZE="2"> 
svm)<br>
Removes an object from the map.&nbsp; SVMapObject is a base class that all map 
objects descend from, including StarShips, StarSystems, Pulsars, BlackHoles, Wormholes, 
and <a href="UDOs.htm">UDOs</a>.&nbsp; So, you can pass any of these objects into this method to 
remove them from play.</font></p>
<font SIZE="2" COLOR="#00FFFF"><b>
<p>public</b> <b>void</b></font><font SIZE="2"> SetBlackHoleRadius(</font><font SIZE="2" COLOR="#00FFFF">BlackHole</font><font SIZE="2"> 
bh, </font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> 
radius)<br>
Allows you to dynamically change the radius of a BlackHole.</p>
</font>
<font SIZE="2" COLOR="#00FFFF"><b>
<p>public</b> <b>void</b></font><font SIZE="2"><font color="#00FFFF"> </font>
SetTerrain(</font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> 
x, </font><font SIZE="2" COLOR="#00FFFF"><b>int</b></font><font SIZE="2"> y,
</font><font SIZE="2" COLOR="#00FFFF"><b>char</b></font><font SIZE="2"> terrain)<br>
Allows you to change terrain on the map dynamically.&nbsp; The current supported 
terrains are an empty space (' ') for clear terrain, and 'N' for Nebula.</font></p>
<p><font color="#FFFF00"><b>Passing Scenario Information to other Players</b></font></p>
<p>In MultiPlayer games it can be important to properly synchronize data needed 
in the ProcessImpulse method with the clients in the game.&nbsp; Only the game's 
&quot;host&quot; player gets the ProcessImpulse called every Impusle, and communicates any 
dynamic changes to other players via the DynamicEvents methods.&nbsp; If the 
host player is eliminated, then one of the other players assumes the role of the 
host.&nbsp; If the Scenario relies on variables initialized during the 
BuildScenario method, or previous calls to ProcessImpulse, then the new host 
will be &quot;out of synch&quot; and the Scenario may not work correctly after the 
transition.</p>
<p>To avoid this, you should pass required information to the other players by 
calling SetValue (see <a href="Scenario%20Programming.htm">Scenario Programming</a> 
for details of this method.)&nbsp; Each required piece of information should be 
encoded in a string and persisted with a SetValue call.&nbsp; You can also call 
SetValue during a game from within the ProcessImpulse method, the values will be 
communicated to other players.</p>
<p>When another player joins the game, their Scenario object calls 
PostLoadInitialize, instead of BuildScenario.&nbsp; Within PostLoadInitialize, 
you can call GetValue to read the values that were communicated from the game 
host's calls to SetValue.&nbsp; In this way you can ensure that the game clients 
are passed any required information that was determined in the host's 
BuildScenario method.</p>
<p>The Scenario PsiWars.cs uses this mechanism to flag which StarSystems give 
birth to RemoteViewers.&nbsp; In the Scenario code, this information is read by 
the clients in the PostLoadInitialize method so they can update their internal 
data structures.&nbsp; If the host player is eliminated, one of the clients will assume 
the role of the host and have the correct data ready when their ProcessImpulse 
calls happen.</p>
<p>&nbsp;</p>
</font>

</body>

</html>